<template>
  <div class="books">
    <my-header>
      <template #center> 我的书架 </template>
      <template #left>
        <span class="left" @click="$router.back()"> 返回 </span>
      </template>
    </my-header>
    <div style="margin-top: 10px">
      <section>
        <p :style="{ background: $store.state.useColor }">
          <span>正在看</span> <span>></span>
        </p>
        <ul>
          <template v-for="(item, index) in bookList">
            <li :key="index" v-if="item.state == 0">
              <span>{{ item.name }}</span>
              <div>
                <span style="color: red" @click="$store.commit('cutState',index)">标记为已看完</span> |
                <span style="color: #ccc" @click="$store.commit('del',index)">删除此书</span>
              </div>
            </li>
          </template>
        </ul>
      </section>
      <section>
        <p :style="{ background: $store.state.useColor }">
          <span>已完结</span> <span>></span>
        </p>
        <ul>
          <template v-for="(item, index) in bookList">
            <li :key="index" v-if="item.state == 1">
              <span>{{ item.name }}</span>
              <div>
                <span style="color: red" @click="$store.commit('cutState',index)">在看一遍</span> |
                <span style="color: #ccc" @click="$store.commit('del',index)">删除此书</span>
              </div>
            </li>
          </template>
        </ul>
      </section>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs, computed } from "vue";
import myHeader from "../components/myHeader.vue";
import { useStore } from "vuex";
export default {
  components: { myHeader },
  setup() {
    const store = useStore();
    const data = reactive({
      bookList: computed(() => store.state.books),
    });
    return {
      ...toRefs(data),
    };
  },
};
</script>
<style lang="scss" scoped>
.books {
  height: 100%;
}
.left {
  font-size: 12px;
  color: rgb(7, 7, 177);
}
section {
  p {
    height: 40px;
    padding: 0 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
  }
  li {
    height: 40px;
    padding: 0 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>